package demo2;

/**
 * 栈上分配
 *
 * @author lfg
 * @version 1.0
 */
public class 栈上分配 {

    private static User 非逃逸对象 = new User();

    //-server
    //-XX:+DoEscapeAnalysis
    //-Xmx100m
    //-Xms50m
    //-XX:+PrintGC

    public static void main(String[] args) {
        for (int i = 0; i < 99999999; i++) {
//            栈上分配();
            堆上分配();
        }

    }

    public static void 栈上分配() {
        User 逃逸对象 = new User();
        逃逸对象.id = 999L;
        逃逸对象.name = "张三";
    }

    public static void 堆上分配() {
        非逃逸对象.id = 999L;
        非逃逸对象.name = "张三";
    }

}



